﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using UT3Bots.UTItems;
using UT3Bots.Communications;

namespace UT3Bots.Visualizer.Visualizer.UTItems
{
	public class UTUIScore : IComparable<UTPlayerScore>, IComparable<UTUIScore>, INotifyPropertyChanged
	{

		//Private members
		private UTIdentifier _id;
		private string _name;
		private int _score;
		private int _position;
		private UTBotOppState _bot;
		private DateTime _lastUpdated;


		#region Properties
		public UTIdentifier Id
		{
			get { return this._id; }
		}

		public string Name
		{
			get { return this._name; }
		}

		public int Score
		{
			get { return this._score; }
		}

		public int Position
		{
			get { return this._position; }
			internal set
			{
				this._position = value;
				OnPropertyChanged("Position");
			}

		}

		public UTBotOppState Bot
		{
			get { return this._bot; }
		}


		public DateTime LastUpdated
		{
			get { return this._lastUpdated; }
		}
		#endregion



		internal UTUIScore(UTIdentifier Id, string Name, int Score)
		{
			this._id = Id;
			this._name = Name;
			this._score = Score;

		}



		internal void SetScore(int NewScore)
		{
			this._score = NewScore;
			this._lastUpdated = DateTime.Now;
			OnPropertyChanged("Score"); 
		}

		internal void SetPosition(int NewPosition)
		{
			this._position = NewPosition;
			OnPropertyChanged("Position");
		}

		internal void SetBot(UTBotOppState Bot)
		{
			this._bot = Bot;
			//OnPropertyChanged("Bot");
		}


		public override string ToString()
		{

			return this._id.ToString().PadRight(30) + " " + this._name.PadRight(30) + " " + this._score;
		}




		#region IComparable<UTPlayerScore> Members

		public int CompareTo(UTPlayerScore other)
		{
			if (this._score > other.Score)
			{
				return -1;
			}
			else if (this._score < other.Score)
			{
				return 1;
			}
			else
			{
				return this._id.CompareTo(other.Id);
			}
		}

		public int CompareTo(UTUIScore other)
		{
			if (this._score > other._score)
			{
				return -1;
			}
			else if (this._score < other._score)
			{
				return 1;
			}
			else
			{
				return this._id.CompareTo(other._id);
			}
		}

		#endregion



		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void OnPropertyChanged(string propName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propName));
		}

		#endregion


	}
}
